package com.groupalpha.helpers;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.groupalpha.studentport.R;

public class ExamsAdapter extends ArrayAdapter<Tenta> {
	 
    Context context;
 
    public ExamsAdapter(Context context, int resourceId,
            List<Tenta> items) {
        super(context, resourceId, items);
        this.context = context;
    }
 
    /*private view holder class*/
    private class ViewHolder {
        
        TextView txtKursKod;
        TextView txtKurs;
        TextView txtDatum;
        TextView txtPlats;
        TextView txtTid;
        
        
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        Tenta tenta = getItem(position);
 
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.exam_item, null);
            holder = new ViewHolder();
            holder.txtKursKod = (TextView) convertView.findViewById(R.id.tv_kurskod);
            holder.txtKurs = (TextView) convertView.findViewById(R.id.tv_kurs);
            holder.txtDatum = (TextView) convertView.findViewById(R.id.tv_datum);
            holder.txtPlats = (TextView) convertView.findViewById(R.id.tv_plats);
            holder.txtTid = (TextView) convertView.findViewById(R.id.tv_tid);
            
           
            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();
 
        holder.txtKursKod.setText(tenta.getKursKod());
        holder.txtKurs.setText(Html.fromHtml(tenta.getKursNamn()).toString());
        holder.txtDatum.setText(tenta.getDatum());
        holder.txtPlats.setText(tenta.getPlats());
        holder.txtTid.setText(tenta.getKursStart());
 
        return convertView;
    }
}
